const db = require('../db/index');

class indexService {
  getFileInfo(status, cb) {
    try {
      const statement = `SELECT * FROM act_video WHERE status = ? ORDER BY start_time ASC;`;
      return db.query(statement, [status], function (err, results, fields) {
        if (err) throw err;
        cb(results);
        return results;
      });
    } catch (error) {
      console.log(error);
    }
  }

  updateFileInfo(update, file_id, cb) {
    // [move_video_url, status, move_time, cause, file_id];
    // [status, cause, file_id];
    const statement = `UPDATE act_video SET ? WHERE file_id = ? `;
    try {
      return db.query(statement, [update, file_id], function (err, results, fields) {
        if (err) throw err;
        cb(results);
        return results;
      });
    } catch (error) {
      console.log(error);
    }
  }

  batchInsertMoments(inserts) {
    try {
      const statement = `INSERT INTO act_video (file_id, start_time, video_url, Type) VALUES ?;`;
      db.query(statement, [inserts], function (err, results, fields) {
        if (err) throw err;
        console.log('The solution is: ', results);
        return results;
      });
    } catch (error) {
      console.log(error);
    }
  }
}

module.exports = new indexService();
